begintownscript;

variables;
short priestpc,cancast;

body;

beginstate 0;

	add_char_to_group(6,1);
	add_char_to_group(7,1);
	add_char_to_group(8,1);
	add_char_to_group(9,1);
	add_char_to_group(10,1);
	add_char_to_group(11,1);
	add_char_to_group(12,1);
	add_char_to_group(13,1);
	add_char_to_group(14,1);
	add_char_to_group(15,1);
	add_char_to_group(16,1);
	add_char_to_group(17,1);
	add_char_to_group(18,1);

	add_char_to_group(19,2);
	add_char_to_group(20,2);
	add_char_to_group(21,2);
	add_char_to_group(22,2);
	add_char_to_group(23,2);
	add_char_to_group(24,2);
	add_char_to_group(25,2);
	add_char_to_group(26,2);
	add_char_to_group(27,2);
	add_char_to_group(28,2);

	add_char_to_group(29,3);
	add_char_to_group(30,3);
	add_char_to_group(31,3);
	add_char_to_group(32,3);
	add_char_to_group(33,3);

	add_char_to_group(39,4);
	add_char_to_group(39,4);
	add_char_to_group(40,4);

	add_char_to_group(36,5);
	add_char_to_group(37,5);
	add_char_to_group(41,5);
	add_char_to_group(42,5);
	add_char_to_group(43,5);
	add_char_to_group(44,5);
	add_char_to_group(45,5);
	add_char_to_group(46,5);
	add_char_to_group(47,5);

	if(get_flag(2,1) < 64){
		force_instant_terrain_redraw();
		message_dialog("The Goblin Village doesn't look like much of a village.  There are impressive banners and a thick wall, but the structures appear to be ruined.","The goblins couldn't have built the entire structure.  It appears as if this village once belonged to a very powerful tribe.");
		message_dialog("The goblins, then, must have squatted on the old tribe's village after they died or moved on.  Since then, the goblins have been letting the village decay.","A large party of fighters stand on poorly-constructed mounds of dirt on either side of you, and are plenty angry that you have entered their village.  Time to fight.");
		set_flag(2,1,64);
	}

	priestpc = 0;
	cancast = 0;
	while(priestpc < 4 && cancast == 0){
			if(char_ok(priestpc) == TRUE){
if(get_stat(priestpc,12) >= 7 && get_spell_level(priestpc,1,9) >= 1){
	cancast = 1;
}
			}
priestpc = priestpc + 1;
	}
	if(cancast == 0){
		set_terrain(39,40,54);
	}

	if(get_flag(16,1) >= 1){
		set_terrain(42,35,0);
	}

	if(get_flag(17,1) >= 1){
		set_terrain(43,35,0);
	}

break;

beginstate 1;

	if(get_flag(16,1) == 0 && get_terrain(42,35) != 36){
		set_flag(16,1,1);
	}
	if(get_flag(17,1) == 0 && get_terrain(43,35) != 36){
		set_flag(17,1,1);
	}

break;

beginstate START_STATE;
break;

beginstate 10;

	if(get_flag(2,1) == 64){
		message_dialog("There is a passage in the side of the mountains here.  You could slip through, were it not for a shoddy but effective wall erected to inhibit your progress.","Maybe this is how the goblins managed to take over the other tribe, or at least infiltrate its village.  Maybe not.  Point is, you'll have to find some way to continue.");
		set_flag(2,1,65);
	}

break;

beginstate 11;

	if(is_combat() == 1){
		print_str_color("Can't leave town in combat mode.",1);
		block_entry(1);
		end();
	}

	move_to_new_town(3,24,43);

break;